import {
	ajax as commonAjax,
	getUserInfo
} from '@/common/common.js'
import {
	bpmUrl
} from "@/common/config.js"
// js封装所需
function ajax(opt) {
	return new Promise((resolve, reject) => {
		let complete = (complete) => {
			if (opt.complete) {
				opt.complete(complete)
			}
			resolve(complete)
		}
		try {
			commonAjax({ ...opt,
				complete
			})
		} catch (e) {
			reject()
		}
	})
}
//初始赋值
function formonload(list, formData, bussiness) {
	list.forEach(item => {
		if (['staff_name', 'dept'].indexOf(item.name) != -1) {
			item.disabled = true
		}
	})
	return list
}

function staffNoChange(val, formData) {
	let paramas = {
		headersMap: {
			sysid: "bpm",
			syspwd: "pass",
			userid: user.bpmUid
		}
	}
	ajax({
		url: '/bpm/get',
		method: 'POST',
		data: {
			...paramas,			
			paramasMap: {
				staff_no: val,
			},
			url: bpmUrl + '/rest/appform/R_hra/R_hra_P011'
		},
		success: res => {
		}
	})
	// 根据staff_no 赋值
	ajax({
		url: '/bpm/get',
		method: 'POST',
		data: {
			...paramas,
			url: bpmUrl + '/rest/appform/R_hra/R_hra_B007'
		},
		success: res => {
			// todo: 赋值
		}
	})
}

function formonsubmit(list, formData, bussiness) {
	let flag = true
	if(!formData.Subject) {
		let processname = bussiness.processname
		formData.Subject = formData.staff_name + processname
	}
	return flag;
}

export default {
	formonload,
	staffNoChange,
	formonsubmit,
}
